
#include "hgeUtil.h"
#include "Application.h"

using namespace std;
vector<TileSet> tileSets;

//
// InitQuad
//

void InitQuad(hgeQuad &q, HTEXTURE tex, DWORD color)
{
	q.blend = BLEND_DEFAULT;
	q.tex = tex;

	for(int i = 0; i < 4; i++)
	{
		q.v[i].col = color;
		q.v[i].z = 0.5f;
	}
}

//
// SetQuadRect
//

void SetQuadRect(hgeQuad &q, float x0, float y0, float x1, float y1)
{
	q.v[0].x = x0;
	q.v[1].x = x1;
	q.v[2].x = x1;
	q.v[3].x = x0;
	
	q.v[0].y = y0;
	q.v[1].y = y0;
	q.v[2].y = y1;
	q.v[3].y = y1;
}

//
// SetQuadTexCo
//

void SetQuadTexCo(hgeQuad &q, float x0, float y0, float x1, float y1)
{
	q.v[0].tx = x0;
	q.v[1].tx = x1;
	q.v[2].tx = x1;
	q.v[3].tx = x0;
	
	q.v[0].ty = y0;
	q.v[1].ty = y0;
	q.v[2].ty = y1;
	q.v[3].ty = y1;
}

//
// TileSet
//

TileSet::TileSet(const char *_filePath)
{
	strcpy(filePath, _filePath);
	tex = hge->Texture_Load(filePath);
	imageSize = (float)hge->Texture_GetWidth(tex);
	setSize = (float)hge->Texture_GetHeight(tex) / imageSize;
}

//
// GetTileSet
//

int GetTileSet(const char *filePath)
{
	// Find the texture
	for(int i = 0; i < int(tileSets.size()); i++)
	{
		if(strcmp(tileSets[i].filePath, filePath))
			return tileSets[i].tex;
	}

	// If not there load it in
	TileSet set(filePath);
	tileSets.push_back(set);

	return tileSets.size()-1;
}
